<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台（PHP版）
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码，建议反馈是我们前进的动力
// | 开源版本可自由商用，可去除界面版权logo
// | gitee下载：https://gitee.com/likeshop_gitee/likeadmin
// | github下载：https://github.com/likeshop-github/likeadmin
// | 访问官网：https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------


namespace app\adminapi\controller;


use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\TbHxwtLists;
use app\adminapi\logic\TbHxwtLogic;
use app\adminapi\logic\TbWorktaskLogic;
use app\adminapi\validate\TbHxwtValidate;
use app\adminapi\validate\TbWorktaskValidate;
use think\helper\Str;


/**
 * TbHxwt控制器
 * Class TbHxwtController
 * @package app\adminapi\controller
 */
class TbHxwtController extends BaseAdminController
{


    /**
     * @notes 获取列表
     * @return \think\response\Json
     * @author likeadmin
     * @date 2025/03/22 11:34
     */
    public function lists()
    {
        return $this->dataLists(new TbHxwtLists());
    }


    /**
     * @notes 添加
     * @return \think\response\Json
     * @author likeadmin
     * @date 2025/03/22 11:34
     */
    public function add()
    {
        $params = (new TbHxwtValidate())->post()->goCheck('add');
        $result = TbHxwtLogic::add($params);
        if (true === $result) {
            return $this->success('添加成功', [], 1, 1);
        }
        return $this->fail(TbHxwtLogic::getError());
    }


    /**
     * @notes 编辑
     * @return \think\response\Json
     * @author likeadmin
     * @date 2025/03/22 11:34
     */
    public function edit()
    {
        $params = (new TbHxwtValidate())->post()->goCheck('edit');
        $result = TbHxwtLogic::edit($params);
        if (true === $result) {
            return $this->success('编辑成功', [], 1, 1);
        }
        return $this->fail(TbHxwtLogic::getError());
    }


    /**
     * @notes 删除
     * @return \think\response\Json
     * @author likeadmin
     * @date 2025/03/22 11:34
     */
    public function delete()
    {
        $params = (new TbHxwtValidate())->post()->goCheck('delete');
        TbHxwtLogic::delete($params);
        return $this->success('删除成功', [], 1, 1);
    }


    public function detail()
    {
        $params = (new TbHxwtValidate())->goCheck('detail');
        $result = TbHxwtLogic::detail($params);

        $key ='detail:'.$params['id'];
        if (cache($key)){
            return $this->data(cache($key));
        }
        $result['bujian'] =  Str::random(8,1);
        $result['KBB'] =  Str::random(8,1);
        $result['kehujian'] =  Str::random(10);
        $result['KBB2'] =  strtoupper(Str::random(15));
        $result['KGB1'] =  strtoupper( Str::random(17));
        $result['KGB2'] =  substr($result['KGB1'],0,3).'****'.substr($result['KGB1'],7,10) ;
        cache($key,$result,86400*30);
        return $this->data($result);
    }

    public function zhenduan()
    {
        $params = (new TbHxwtValidate())->goCheck('detail');
        $result = TbHxwtLogic::detail($params);

        $key ='hxzhenduan42:32'.$params['id'];
        if (cache($key)){
            return $this->data(cache($key));
        }
        $result['e1'] =  Str::random(7,1);
        $result['e2'] =  Str::random(7,1);
        $result['e3'] =  Str::random(7,1);
        $result['e8'] =  Str::random(7,1);
        $result['e10'] =  Str::random(7,1);
        $result['g3'] =  Str::random(1,1);
        $result['g3_time'] =  date('Y-m-d H:i:s');
        $result['weiixu_0'] =  strtoupper( Str::random(8,1));
        $result['weiixu_1'] =  strtoupper( Str::random(8,1));
        $result['e4'] =  strtoupper( Str::random(8,1)) ;
        cache($key,$result,86400*30);
        return $this->data($result);
    }
}